/*
* Nettle Source File.
* Copyright (C) 2013, Nettle (http://nttl.ru/).
*
* This file is part of NettleMath.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Description:
*
* History:
* Created by Sergey Serb, l-proger@yandex.ru
*/

#ifndef NMathUtils_h__
#define NMathUtils_h__

#include "NMathConfig.h"
#include <assert.h>
#include <math.h>
#include <cmath>

namespace NettleMath{
#if defined(NMATH_FEATURE_CXX11)
#define NMATH_STATIC_ASSERT(___expr, ___msg)\
    static_assert(___expr, ___msg);
#else
    assert(##___expr## && ## ___msg);
#endif

#define N_PI 3.1415926535897932384626
#define RAD_TO_DEG(___rad)\
    (___rad * (180.0 / N_PI))

#define DEG_TO_RAD(___deg)\
    (___deg * (N_PI / 180.0))

    template <typename T>
    T sign(T t) {
        if( t == 0 )
            return T(0);
        else
            return (t < 0) ? T(-1) : T(1);
    }

    template <typename T>
    T frac(T t) {
        return t - std::floor(t);
    }

    template<typename T>
    inline T min_internal(T a, T b){
        return a < b ? a : b;
    }

    template<typename T>
    inline T max_internal(T a, T b){
        return a > b ? a : b;
    }

    template<typename T>
    inline T clamp(T v, T min_val, T max_val){
        return min_internal(max_internal(v, min_val), max_val);
    }

#ifdef min
#undef min
#endif

#ifdef max
#undef max
#endif

    

}

#endif // NMathUtils_h__
